#!/usr/bin/python
# -*- coding:utf-8 -*-

import datetime
from app.db import BaseDocument
import mongoengine as db


class DefenseTargets(BaseDocument):
    """ 在云防御使用源站安全检测记录 """

    target_url = db.StringField()
    source_ip = db.StringField()
    target_name = db.StringField()
    createAt = db.DateTimeField()
    user_id = db.ObjectIdField()

    meta = {
        'collection': 'defense_targets',
        'strict': False
    }

    def save(self, *args, **kwargs):
        if not self.createAt:
            self.createAt = datetime.datetime.utcnow()
        return super(DefenseTargets, self).save(*args, **kwargs)
